import { getOrderList } from '../../model/order';

const app = getApp<IAppOption>();

Page({
  data: {
    activeTab: 'all',
    list: [] as any[]
  },
  toOrderDetail(event: any) {
    const orderId = event.target.dataset.id;
    wx.navigateTo({
      url: '/pages/order-detail/order-detail?id=' + orderId
    });
  },
  handleTabChange(event: any) {
    const tab = event.detail.name;
    this.getOrders(tab);
  },
  async getOrders(activeTab: string) {
    const statue = activeTab === 'all' ? undefined : Number(activeTab);
    const openId = app.globalData.openId;
    const params: any = { open_id: openId };
    statue && (params.statue = statue);
    const data = await getOrderList(params);

    this.setData({
      list: data
    });
  },
  onLoad: async function () {
    this.getOrders(this.data.activeTab);
  }
});
